//
//  UIImage+LaunchImage.m
//  Yunxiaoyuan
//
//  Created by 刘 真 on 21/09/2016.
//  Copyright © 2016 Talkweb. All rights reserved.
//

#import "UIImage+LaunchImage.h"

@implementation UIImage (LaunchImage)

+ (UIImage *)launchImage {
    NSDictionary *dict = [[NSBundle mainBundle] infoDictionary];
    NSArray *launchImages = dict[@"UILaunchImages"];
    
    CGFloat version = [[[UIDevice currentDevice] systemVersion] floatValue];
    CGSize size = [UIScreen mainScreen].bounds.size;
    
    NSString *orientation = @"Portrait";
    switch ([UIApplication sharedApplication].statusBarOrientation) {
        case UIInterfaceOrientationLandscapeLeft:
        case UIInterfaceOrientationLandscapeRight:
            orientation = @"Landscape";
            break;
        default:
            break;
    }
    
    for (NSDictionary *item in launchImages) {
        CGFloat v = [item[@"UILaunchImageMinimumOSVersion"] floatValue];
        CGSize s = CGSizeFromString(item[@"UILaunchImageSize"]);
        NSString *o = item[@"UILaunchImageOrientation"];
        if (version >= v && CGSizeEqualToSize(size, s) && [orientation isEqualToString:o]) {
            return [UIImage imageNamed:item[@"UILaunchImageName"]];
        }
    }
    return nil;
}

@end
